//
//  UIBarButton+Extenstion.swift
//  CustomWeiBo
//
//  Created by laiqiang on 21/5/10.
//  Copyright © 2021年 laiqiang. All rights reserved.
//

import Foundation

extension UIBarButtonItem {
    
    ///使用便利构造函数创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - font: fontsize 默认16
    ///   - targe: targe
    ///   - action: action
    ///   - isBack: is navgationBar back button
    //    - return: UIBarButtonItem
    
    convenience init(title:String,font:CGFloat = 16,targe:AnyObject?,action:Selector ,isBack:Bool = false) {
        
        let btn = UIButton(frame: CGRect(x: 0, y: 0, width: 50, height: 40))
        btn.titleLabel?.font = UIFont.systemFont(ofSize: font)
        btn.setTitle(title, for: .highlighted)
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor().WBPinkColor, for: .highlighted)
        btn.setTitleColor(UIColor.black, for: .normal)
        btn.addTarget(targe, action:action, for:.touchUpInside)
        btn.sizeToFit()
        
        if isBack == true {
            
            let imgName = "nav_back"
            btn.setImage(UIImage.init(named: imgName), for: .normal)
            btn.setImage(UIImage.init(named: imgName), for: .highlighted)
            btn.sizeToFit()
        }
        
        //实例化uibarbutton
        self.init(customView: btn)

    }

    


}
